local skel = fk.CreateSkill {
  name = "kpaI__juanwo",
}

Fk:loadTranslationTable{
  ["kpaI__juanwo"] = "卷涡",
  [":kpaI__juanwo"] = "其他角色回合开始时，你可摸一或两张牌，本回合其造成X次伤害后，其对你造成X点伤害（X为另一值）。",

  ["#kpaI__juanwo"] = "卷涡：你可摸一或两张牌，本回合其造成X次伤害后，其对你造成X点伤害（X为另一值）",

  ["@kpaI__juanwo_dam-turn"] = "卷涡",

}

skel:addEffect(fk.TurnStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target ~= player
  end,
  on_cost = function (self, event, target, player, data)
    local choose = player.room:askToChoice(player,{
      choices = {"1","2","Cancel"},
      prompt = "#kpaI__juanwo",
      cancelable = true,
      skill_name = skel.name
    })
    if choose ~= "Cancel" then
      if choose == "1" then
        event:setCostData(self,{choice = 1})
      else
        event:setCostData(self,{choice = 2})
      end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = event:getCostData(self).choice
    local room = player.room
    local to = room:getCurrent()
    room:drawCards(player,n)
    room:setPlayerMark(to,"@kpaI__juanwo_dam-turn",3-n)
    room:setPlayerMark(to,"kpaI__juanwo_damto-turn",player.id)
    room:setPlayerMark(to,"kpaI__juanwo_damn-turn",3-n)
  end,
})

skel:addEffect(fk.Damage,{
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@kpaI__juanwo_dam-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:getMark("@kpaI__juanwo_dam-turn") == 1 then
      room:setPlayerMark(player,"@kpaI__juanwo_dam-turn",0)
      local to = room:getPlayerById(player:getMark("kpaI__juanwo_damto-turn"))
      local n = player:getMark("kpaI__juanwo_damn-turn")
      room:setPlayerMark(player,"kpaI__juanwo_damto-turn",0)
      room:setPlayerMark(player,"kpaI__juanwo_damn-turn",0)
      room:damage({
        from = player,
        damage = n,
        to = to,
        skillName = skel.name,
      })
    else
      room:setPlayerMark(player,"@kpaI__juanwo_dam-turn",player:getMark("@kpaI__juanwo_dam-turn") - 1)
    end
  end
})

return skel
